package logic

import (
	"context"
	"fmt"
	"home-mgr/model"
	"strings"

	"home-mgr/homerpc/homerpc"
	"home-mgr/homerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SpekAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSpekAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SpekAddLogic {
	return &SpekAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SpekAddLogic) SpekAdd(in *homerpc.SpekAddRequest) (*homerpc.SpekAddResponse, error) {
	// todo: add your logic here and delete this line

	spek := model.Spek{

		UserId:  int(in.UserId),
		HouseId: int(in.HouseId),
		Text:    in.Text,
	}
	if strings.Contains("中介费", in.Text) {
		return nil, fmt.Errorf("含违规内容")
	}
	model.DB.Debug().Create(&spek)
	return &homerpc.SpekAddResponse{
		SpekId: int64(spek.ID),
	}, nil
}
